package com.wzq.solution;

import com.wzq.solution.node.ListNode;

class Solution206 {
    public static ListNode reverseList(ListNode head) {
        
        ListNode newList = null;
        
        while(head != null){
            ListNode p = head;
            head = head.next;
            p.next = newList;
            newList = p;

        }
        return newList;
        
    }

    public static void main(String[] args) {
        int[] headArr = new int[]{1,2,3,4,5};
        ListNode head = new ListNode(headArr[0]);
        ListNode p =head;
        for (int i=1;i<headArr.length; i++){
            p.next = new ListNode(headArr[i]);
            p = p.next;
        }

        head = reverseList(head);
        while (head != null){
            System.out.println(head.val);
            head = head.next;
        }
        //System.out.println(964632435*10+1>Math.pow(2,31)-1);
    }
}